package com.jshcbd.modules.asset.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jshcbd.modules.asset.entity.RepairEntity;
import com.jshcbd.modules.asset.vo.AssetRepairVo;
import com.jshcbd.modules.asset.vo.RepairVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author zhoucd
 * @date
 * @description
 */
public interface RepairMapper extends BaseMapper<RepairEntity> {

    @Select("SELECT * FROM (SELECT A.ID,A.ASSET_ID,A.NOTE,A.START_DATE,A.FINISH_DATE,A.PHONE,A.CONTACTS,A.ACCEP_PHOTO,A.CREATE_TIME,A.REPAIR_STATE," +
            "B.CONTRACT_NAMBER,B.NUMBER,B.IN_DATE,B.BATCH,B.NAME,B.BUYER,B.UNIT,B.MODEL,B.STATE,B.USEFUL_LIFE, " +
            "B.MANUFACTURER,B.PRICE,B.IS_FAX,B.IS_FIXED,B.PHOTO,B.START_USETIME,B.DEPRECIATION,B.DEPRECIATION_WAY,B.RECEIVE_ID," +
            "B.CLASSES_ID,B.RFID,B.DIS_DATE,B.USE_STATE," +
            "C.RECEIVER,C.TELPHONE,C.COMPANY_ID,C.DUE_DATE,C.SUM_PRICE,C.NOTE RECEIVE_NOTE,D.NAME COMPANY_NAME," +
            "E.CODE,E.CLASSES,E.TYPE_NAME,E.DEPRECIATION_MONTH " +
            "FROM  REPAIR  A " +
            "LEFT JOIN ASSET B ON  A.ASSET_ID = B.ID " +
            "LEFT JOIN RECEIVE C ON B.RECEIVE_ID = C.ID " +
            "LEFT JOIN COMPANY D ON C.COMPANY_ID = D.ID " +
            "LEFT JOIN CLASSES E ON B.CLASSES_ID = E.ID ) TEMP " +
            " ${ew.customSqlSegment}")
    Page<RepairVo> selectPageView(Page<RepairVo> page, @Param(Constants.WRAPPER) Wrapper wrapper);


    @Select("SELECT * FROM REPAIR WHERE ASSET_ID = #{assetId} ")
    IPage<AssetRepairVo> pageViewByAssetId(Page<AssetRepairVo> page, String assetId);
}
